package net.ib.mtalk.ui.buddy.talk;

import net.ib.mtalk.R;
import net.ib.mtalk.base.BaseActivity;
import net.ib.mtalk.util.GpbSupport;
import net.ib.mtalk.util.ProfileImageLoader;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ProfileImageView extends BaseActivity {
	private static int PROGRESSBAR = 1;
	private Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mContext = this;
		Intent intent = getIntent();
		long msb = intent.getLongExtra("msb", 0);
		long lsb = intent.getLongExtra("lsb", 0);
		
		RelativeLayout layout = new RelativeLayout(this);
		layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		final Button button = new Button(this);
		
		ImageView imageView = new ImageView(this);
		imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		button.setText(getString(R.string.ok));
		button.setTextColor(Color.BLACK);
		
		ProgressBar progressBar = new ProgressBar(this);
		progressBar.setId(PROGRESSBAR);
		TextView textView = new TextView(this);
		textView.setText("Waiting...");
		
		RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params1.addRule(RelativeLayout.CENTER_IN_PARENT);
		layout.addView(progressBar, params1);
		
		RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params2.addRule(RelativeLayout.BELOW, progressBar.getId());
		params2.addRule(RelativeLayout.CENTER_HORIZONTAL);
		layout.addView(textView, params2);
		
		ProfileImageLoader.getInstance(mContext).loadProfileImage(imageView, 
				GpbSupport.UuidMsgToString(GpbSupport.makeUuidMsg(msb, lsb)));
		layout.addView(imageView, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		RelativeLayout.LayoutParams params3 = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		layout.addView(button, params3);
		
		setContentView(layout);
		
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				button.setSelected(true);
				finish();
			}
		});
		
//		Bitmap profile = ProfileDownloader.getInstance(this).getProfile(sid);
//		Bitmap profile = null;
//		if(profile == null){
//			imageView.setImageResource(R.drawable.skin0_default_profile);
//		} else{
////			SMSGraphicUtil.getBigProfile(this, sid, imageView);
//		}
	}
}
